import {
	BaseUrl,
	formatDishesScore
} from "./config"

export function getDishByDishId(dishId) {
	return uni.request({
		method: "POST",
		url: BaseUrl + '/dishes/getDishById',
		data: {
			id: dishId
		}
	}).then(res => {
		// console.log("getDishByDishId111", );
		// return res.data;
		return {
			data: formatDishesScore([res.data.data])[0]
		}
	})
}

export function getDishesByDishTypeId(dishTypeId) {
	return uni.request({
		method: "POST",
		url: BaseUrl + '/dishes/getByDishTypeId',
		data: {
			dishTypeId,
			pageNumber: 1,
			pageSize: 300
		}
	}).then(res => {
		const data = res.data.data;
		const dishes = formatDishesScore(data.data);
		return dishes;
	})
}

export function createDish({
	dishTypeId,
	name,
	description,
	imageUrl
}) {
	return uni.request({
		method: "POST",
		url: BaseUrl + "/dishes/create",
		data: {
			dishTypeId,
			name,
			description,
			imageUrl
		}
	}).then(res => res.data)
}

export function updateDish({
	id,
	name,
	dishTypeId,
	description,
	imageUrl
}) {
	return uni.request({
		method: "POST",
		url: BaseUrl + "/dishes/updateDishById",
		data: {
			id,
			name,
			dishTypeId,
			description,
			imageUrl
		}
	}).then(res => res.data)

}

export function deleteDishById(dishId) {
	return uni.request({
		method: "POST",
		url: BaseUrl + "/dishes/deleteDishById",
		data: {
			id: dishId
		}
	}).then(res => res.data)
}